package com.example.musicplayer.activity;

import android.content.Intent;
import android.os.Bundle;

import com.example.musicplayer.R;
import com.example.musicplayer.settings.SettingsItem;
import com.example.musicplayer.user.User;
import com.example.musicplayer.view.SettingsView;

public class SecuritySettingsActivity extends BaseSettingsActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initSettingsItem();
    }

    @Override
    protected int setActivityTitle() {
        return R.string.title_security_settings_activity;
    }

    private void initSettingsItem() {
        setSettingsItem(SettingsItem.MODIFY_PASSWORD);
        setSettingsItem(SettingsItem.SET_PASSWORD_PROTECT);
    }

    @Override
    protected void updateSettingsItem(SettingsView settingsView) {
        super.updateSettingsItem(settingsView);
        if (settingsView.getSettingsItem() == SettingsItem.SET_PASSWORD_PROTECT) {
            String question = User.getInstance().getPasswordProtect();
            settingsView.setDescription(question.equals("") ? getString(R.string.password_protect_not_set)
                    : getString(R.string.password_protect_set));
        }
    }

    @Override
    protected void onSettingsItemClick(SettingsView settingsView, boolean isChecked) {
        super.onSettingsItemClick(settingsView, isChecked);
        Intent intent;
        switch (settingsView.getSettingsItem()) {
            case SettingsItem.MODIFY_PASSWORD:
                intent = new Intent(this, PasswordConfirmActivity.class);
                intent.putExtra(PasswordConfirmActivity.CONFIRM_ACTION, SettingsItem.MODIFY_PASSWORD);
                startActivity(intent);
                break;
            case SettingsItem.SET_PASSWORD_PROTECT:
                intent = new Intent(this, PasswordConfirmActivity.class);
                intent.putExtra(PasswordConfirmActivity.CONFIRM_ACTION, SettingsItem.SET_PASSWORD_PROTECT);
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}